package com.yang.project.base.optional;

import java.util.Optional;

public class OptionalTest {
    public static void main(String[] args) {
        Optional<Object> empty = Optional.empty();
        System.out.println("empty: " + empty);

        Person person = new Person("张三", 11);
        Optional<Person> optionalPerson = Optional.of(person);
        System.out.println("optional: " + optionalPerson);
//        Optional<Object> objectOptional = Optional.of(null);
//        System.out.println("optional: " + objectOptional);

        String s = "hello";
        Optional.ofNullable(s).ifPresent(System.out::println);
        Optional.ofNullable(null).ifPresent(System.out::println);

        Object o = Optional.ofNullable(null).orElse("wozhendeshi");
        System.out.println(o);

    }
}
